package com.wd.demo1.utils;

import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;

/**
 * @author lww
 * @date 2025-10-28 16:03
 */
public class FileChooseUtils {

	private final Project project;

	private FileChooseUtils(Project project) {
		this.project = project;
	}

	public static FileChooseUtils getInstance(Project project) {
		if (project == null) {
			return null;
		}
		return new FileChooseUtils(project);
	}

	public VirtualFile showSingleFileSelectionDialog(String title, VirtualFile toSelect) {
		if (title == null) {
			return null;
		}
		FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor();
		descriptor.setTitle(title);
		return FileChooser.chooseFile(descriptor, this.project, toSelect);
	}
}
